<?php
// +----------------------------------------------------------------------
// | QSCMS
// +----------------------------------------------------------------------
// | Copyright (c)  2025 https://www.qqss.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed QSCMS is not free software, commercial use must purchase official license from official website to avoid unnecessary legal disputes.
// +----------------------------------------------------------------------
// | Author: Contract 990504246@qq.com
// +----------------------------------------------------------------------

namespace app\adminapi\validate\setting;

use taoser\Validate;

class MenuValidate extends Validate
{
    protected $rule = [
        'title'     => 'require',
        'path'      => 'require',
        'component' => 'require',
        'icon'      => 'require',
        'orderNo'   => 'require',
        'perms'     => 'require',
        'type'      => 'require',
        'redirect'  => 'requireCallback:check_require',
    ];

    protected $message = [
        'title.require'            => 'menu_title_required',
        'path.require'             => 'menu_path_required',
        'component.require'        => 'menu_component_required',
        'icon.require'             => 'menu_icon_required',
        'orderNo.require'          => 'menu_orderNo_required',
        'perms.require'            => 'menu_perms_required',
        'type.require'             => 'menu_type_required',
        'redirect.requireCallback' => 'menu_redirect_required',
    ];

    protected function check_require($value, $data)
    {
        if (empty($data['redirect']) && empty($data['pid'])) {
            return true;
        }
    }

    public function sceneMenu()
    {

        $this->only(['title', 'path', 'component', 'type']);
    }

    public function sceneList()
    {
        $this->only(['title', 'path', 'type', 'redirect']);
    }

    public function sceneButton()
    {
        $this->only(['title', 'perms']);
    }
}